package com.atguigu.Flink.datastream.source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.connector.source.Source;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import javax.activation.FileDataSource;
import java.util.Arrays;
import java.util.List;

public class Flink01_SimpleSource {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        //从集合中读取数据
        List<Integer> integers = Arrays.asList(96, 97, 98, 99, 100);
        DataStreamSource<Integer> ds = env.fromCollection(integers);
        ds.print();

        //从文件中读数据
        DataStreamSource<String> ds1 = env.readTextFile("Input/words.txt");
        //ds1.print();

        FileSource<String> build = FileSource.<String>forRecordStreamFormat(new TextLineInputFormat(),new Path("Input/words.txt")).build();

        DataStreamSource<String> ds2 = env.fromSource(build, WatermarkStrategy.noWatermarks(),"file");
        ds2.print();


        try {
            env.execute();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
